let util = require('../../util/util')
const app = getApp();
Page({
    data: {
        collectList: [],
    },
    onLoad() {
        this.getCollectionList();
    },
    getCollectionList() {
        wx.cloud.callFunction({
            name: 'getVideoFun',
            data: {
                fun_name: "get_openid_video_list",
                collection_name: "collectData",
                open_id: app.globalData.userInfo.openid
            },
            success: res => {
                let collectList = res.result.data;
                this.setData({
                    collectList: collectList
                })
            },
            fail: err => {
                util.errorModal(err);
            }
        })
    },
    deleteCollect(evt) {
        wx.showModal({
            title: '温馨提示',
            content: '确定要删除吗？',
            showCancel: true,
            cancelText: '取消',
            cancelColor: '#000000',
            confirmText: '确定',
            confirmColor: '#FF0000',
            success: (result) => {
                if (result.confirm) {
                    wx.cloud.callFunction({
                        name: 'deleteVideoFun',
                        data: {
                            fun_name: 'delete_id_video',
                            collection_name: 'collectData',
                            params: {
                                open_id: app.globalData.userInfo.openid,
                                id: evt.currentTarget.dataset.id,
                            }
                        },
                        success: res => {
                            this.getCollectionList();
                        }, fail: err => {
                            util.errorModal(err);
                        }
                    })
                }
            },
        });

    },
    playVideo(evt) {
        wx.navigateTo({
            url: `../playing/playing?nowCurrentId=${evt.currentTarget.dataset.id}`,
        })
    },
})